﻿<%@ Page Title="Quản lý khách hàng" Language="C#" MasterPageFile="~/OneColumn.Master" AutoEventWireup="true" CodeBehind="Customer.aspx.cs" Inherits="KCL.Organization.CustomerManagement" %>
<asp:Content ID="Content1" ContentPlaceHolderID="PageTitle" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="PageHeader" runat="server">
	<link type="text/css" href="../styles/themes/base/jquery.ui.all.css" rel="stylesheet" />
	<style type="text/css">
		.icon-save
		{
			margin-left: 270px;
			font-size: larger !importtant;
		}
	</style>
	<script type="text/javascript" src="../styles/ui/jquery.ui.core.js"></script>
	<script type="text/javascript" src="../styles/ui/jquery.ui.widget.js"></script>
	<script type="text/javascript" src="../styles/ui/jquery.ui.position.js"></script>
	<script type="text/javascript" src="../styles/ui/jquery.ui.mouse.js"></script>
	<script type="text/javascript" src="../styles/ui/jquery.ui.draggable.js"></script>
	<script type="text/javascript" src="../styles/ui/jquery.ui.dialog.js"></script>
	<script type="text/javascript" src="../styles/ui/jquery.ui.button.js"></script>
	<script type="text/javascript" src="../styles/external/jquery.bgiframe-2.1.2.js"></script>
	<script type="text/javascript">
		$(document).ready(function () {
			$("#divCreateCustomer").dialog({
				autoOpen: false,
				modal: true,
				width: 'auto',
				height: 'auto',
				maxHeight: 900,
				title: 'Nhập thông tin khách hàng',
				resizable: false
			});
//			$("#btnSave").button({icons:{primary:"ui-icon-disk"}});
		});
		function SubmitCustomer() {
			$.ajax({
				url: "Customer.ashx?",
				type: "POST",
				dataType: "script",
				data: {
					name: $("#customerName").val(),
					address: $("#address").val(),
					contactAddress: $("#contactAddress").val(),
					contactPerson: $("#contactPerson").val(),
					phone: $("#phone").val(),
					mobile: $("#mobile").val(),
					fax: $("#fax").val(),
					accountNumber: $("#accountNumber").val(),
					bank: $("#bank").val(),
					taxNumber: $("#taxNumber").val(),
					director: $("#director").val(),
					id: $("#customerId").val(),
					action: $("#action").val()
				}
			});
		}
		function DeleteCustomer(customerId) {
			$.ajax({
				url: "Customer.ashx?",
				type: "POST",
				dataType: "script",
				data: {
					id: customerId,
					action: "delete"
				}
			});
		}
		function DisplayCustomer(id) {
			var currentRow = $("#link" + id).parent().parent().children();
			$('#divCreateCustomer :input[type=text]').each(function (i) { $(this).val($(currentRow[i]).text()); });
			$("#action").val("edit");
			$("#customerId").val(id);
			$("#divCreateCustomer").dialog("open");
		}
		function RefreshCustomer(id) {
			var currentRow = $("#link" + id).parent().parent().children();
			$(currentRow[0]).html($("#customerName").val());
			$(currentRow[1]).html($("#address").val());
			$(currentRow[2]).html($("#contactAddress").val());
			$(currentRow[3]).html($("#contactPerson").val());
			$(currentRow[4]).html($("#phone").val());
			$(currentRow[5]).html($("#mobile").val());
			$(currentRow[6]).html($("#fax").val());
			$(currentRow[7]).html($("#accountNumber").val());
			$(currentRow[8]).html($("#bank").val());
			$(currentRow[9]).html($("#taxNumber").val());
			$(currentRow[10]).html($("#director").val());
		}
		function DisplayCreateCustomer() {
			$('#action').val('create');
			$('#divCreateCustomer :input[type=text]').each(function (){ $(this).val(''); });
			$('#divCreateCustomer').dialog('open');
		}
	</script>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">
	<asp:ObjectDataSource ID="dsCustomer" TypeName="KCL.Code.Data.CustomerDAO" SortParameterName="sortExpression" SelectMethod="GetCustomers" SelectCountMethod="GetTotalCustomer" EnablePaging="true" runat="server"></asp:ObjectDataSource>
	<input type="button" id="btnCreateCustomer" value="Thêm khách hàng" onclick="DisplayCreateCustomer()" />
	<asp:GridView ID="gvCustomer" AllowPaging="true" AllowSorting="true" AutoGenerateColumns="false" BackColor="Wheat" BorderColor="Firebrick" BorderStyle="Ridge" BorderWidth="1px" CellPadding="7" DataSourceID="dsCustomer" GridLines="None" EmptyDataText="" Width="100%" runat="server">
		<HeaderStyle BackColor="Black" ForeColor="Azure" Font-Bold="true" Wrap="false"/>
		<FooterStyle ForeColor="Maroon" BackColor="DarkGoldenrod" />
		<PagerStyle ForeColor="Snow" HorizontalAlign="Right" BackColor="SaddleBrown" />
		<RowStyle BackColor="Ivory" />
		<Columns>
			<asp:BoundField HeaderText="Tên khách hàng" DataField="name" SortExpression="name" />
			<asp:BoundField HeaderText="Địa chỉ" DataField="address" SortExpression="address" />
			<asp:BoundField HeaderText="Địa chỉ liên hệ" DataField="contactAddress" SortExpression="contactAddress" />
			<asp:BoundField HeaderText="Người liên hệ" DataField="contactPerson" SortExpression="contactPerson" />
			<asp:BoundField HeaderText="Số đt" DataField="phone" SortExpression="phone" />
			<asp:BoundField HeaderText="Mobile" DataField="mobile" SortExpression="mobile" />
			<asp:BoundField HeaderText="Fax" DataField="fax" SortExpression="fax" />
			<asp:BoundField HeaderText="Tài khoản" DataField="accountNumber" SortExpression="accountNumber" />
			<asp:BoundField HeaderText="Ngân hàng" DataField="bank" SortExpression="bank" />
			<asp:BoundField HeaderText="Mã số thuế" DataField="taxNumber" SortExpression="taxNumber" />
			<asp:BoundField HeaderText="Giám đốc" DataField="director" SortExpression="director" />
			<asp:BoundField HeaderText="Mã KH" DataField="code" SortExpression="code" />
			<asp:TemplateField HeaderText="Quản lý" ItemStyle-Wrap="false">
				<ItemTemplate>
					<a href="javascript:DisplayCustomer(<%# Eval("id")%>)" id="link<%# Eval("id")%>"><img src="../styles/images/edit.png" alt="Chỉnh sửa" style="border:0; width:16px" /></a><a href="javascript:DeleteCustomer(<%# Eval("id")%>)"><img src="../styles/images/cancel.png" alt="Xóa" style="border:0; width:16px" /></a>
				</ItemTemplate>
			</asp:TemplateField>
		</Columns>
		<AlternatingRowStyle BackColor="SeaShell" />
	</asp:GridView>
	<i>Đang xem trang <%=gvCustomer.PageIndex + 1%> / <%=gvCustomer.PageCount %></i>
	<div id="divCreateCustomer" style="text-align: center">
		<table style="text-align: right; border: 0px; border-spacing: 7px">
			<tr><td>Tên cty</td><td><input type="text" id="customerName" size="70" /></td></tr>
			<tr><td>Địa chỉ</td><td><input type="text" id="address" size="70" /></td></tr>
			<tr><td>Địa chỉ liên hệ</td><td><input type="text" id="contactAddress" size="70" /></td></tr>
			<tr><td>Người liên hệ</td><td><input type="text" id="contactPerson" size="70" /></td></tr>
			<tr><td>Số đt</td><td><input type="text" id="phone" size="70" /></td></tr>
			<tr><td>Mobile</td><td><input type="text" id="mobile" size="70" /></td></tr>
			<tr><td>Fax</td><td><input type="text" id="fax" size="70" /></td></tr>
			<tr><td>Số tài khoản</td><td><input type="text" id="accountNumber" size="70" /></td></tr>
			<tr><td>Ngân hàng</td><td><input type="text" id="bank" size="70" /></td></tr>
			<tr><td>Mã số thuế</td><td><input type="text" id="taxNumber" size="70" /></td></tr>
			<tr><td>Giám đốc</td><td><input type="text" id="director" size="70" /></td></tr>
		</table>
		<button id="btnSave" onclick="SubmitCustomer()" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary"><img src="../styles/images/save.png" alt="Lưu" style="border:0; width:20px; padding: 3px 0px 0px 7px" /><span class="ui-button-text" style="float: right; padding-left: 0.8em">Lưu</span></button>
		<input type="hidden" value="create" id="action" />
		<input type="hidden" value="-1" id="customerId" />
	</div>
</asp:Content>